/**
 * 由 CoCo 源代码计划解包器解包
 *
 * 模块 ID：2234
 */

"use strict"

module.exports = function (e, t, n) {
  var r = " "
  var /* [auto-meaningful-name] */e$level = e.level
  var /* [auto-meaningful-name] */e$dataLevel = e.dataLevel
  var a = e.schema[t]
  var s = e.schemaPath + e.util.getProperty(t)
  var c = e.errSchemaPath + "/" + t
  var u = !e.opts.allErrors
  var l = "data" + (e$dataLevel || "")
  if (false === e.opts.format) {
    if (u) {
      r += " if (true) { "
    }
    return r
  }
  var f
  var d = e.opts.$data && a && a.$data
  if (d) {
    r += " var schema" + e$level + " = " + e.util.getData(a.$data, e$dataLevel, e.dataPathArr) + "; "
    f = "schema" + e$level
  } else {
    f = a
  }
  var /* [auto-meaningful-name] */e$opts$unknownFormats = e.opts.unknownFormats
  var p = Array.isArray(e$opts$unknownFormats)
  if (d) {
    r += " var " + (_ = "format" + e$level) + " = formats[" + f + "]; var " + (A = "isObject" + e$level) + " = typeof " + _ + " == 'object' && !(" + _ + " instanceof RegExp) && " + _ + ".validate; var " + (g = "formatType" + e$level) + " = " + A + " && " + _ + ".type || 'string'; if (" + A + ") { "
    if (e.async) {
      r += " var async" + e$level + " = " + _ + ".async; "
    }
    r += " " + _ + " = " + _ + ".validate; } if (  "
    if (d) {
      r += " (" + f + " !== undefined && typeof " + f + " != 'string') || "
    }
    r += " ("
    if ("ignore" != e$opts$unknownFormats) {
      r += " (" + f + " && !" + _ + " "
      if (p) {
        r += " && self._opts.unknownFormats.indexOf(" + f + ") == -1 "
      }
      r += ") || "
    }
    r += " (" + _ + " && " + g + " == '" + n + "' && !(typeof " + _ + " == 'function' ? "
    if (e.async) {
      r += " (async" + e$level + " ? await " + _ + "(" + l + ") : " + _ + "(" + l + ")) "
    } else {
      r += " " + _ + "(" + l + ") "
    }
    r += " : " + _ + ".test(" + l + "))))) {"
  } else {
    var _
    if (!(_ = e.formats[a])) {
      if ("ignore" == e$opts$unknownFormats) {
        e.logger.warn("unknown format \"" + a + "\" ignored in schema at path \"" + e.errSchemaPath + "\"")
        if (u) {
          r += " if (true) { "
        }
        return r
      }
      if (p && e$opts$unknownFormats.indexOf(a) >= 0) {
        if (u) {
          r += " if (true) { "
        }
        return r
      }
      throw new Error("unknown format \"" + a + "\" is used in schema at path \"" + e.errSchemaPath + "\"")
    }
    var A
    var g = (A = "object" == typeof _ && !(_ instanceof RegExp) && _.validate) && _.type || "string"
    if (A) {
      var v = true === _.async
      _ = _.validate
    }
    if (g != n) {
      if (u) {
        r += " if (true) { "
      }
      return r
    }
    if (v) {
      if (!e.async) {
        throw new Error("async format in sync schema")
      }
      r += " if (!(await " + (m = "formats" + e.util.getProperty(a) + ".validate") + "(" + l + "))) { "
    } else {
      r += " if (! "
      var m = "formats" + e.util.getProperty(a)
      if (A) {
        m += ".validate"
      }
      r += "function" == typeof _ ? " " + m + "(" + l + ") " : " " + m + ".test(" + l + ") "
      r += ") { "
    }
  }
  var y = y || []
  y.push(r)
  r = ""
  if (false !== e.createErrors) {
    r += " { keyword: 'format' , dataPath: (dataPath || '') + " + e.errorPath + " , schemaPath: " + e.util.toQuotedString(c) + " , params: { format:  "
    r += d ? "" + f : "" + e.util.toQuotedString(a)
    r += "  } "
    if (false !== e.opts.messages) {
      r += " , message: 'should match format \""
      r += d ? "' + " + f + " + '" : "" + e.util.escapeQuotes(a)
      r += "\"' "
    }
    if (e.opts.verbose) {
      r += " , schema:  "
      r += d ? "validate.schema" + s : "" + e.util.toQuotedString(a)
      r += "         , parentSchema: validate.schema" + e.schemaPath + " , data: " + l + " "
    }
    r += " } "
  } else {
    r += " {} "
  }
  var b = r
  r = y.pop()
  if (!e.compositeRule && u) {
    if (e.async) {
      r += " throw new ValidationError([" + b + "]); "
    } else {
      r += " validate.errors = [" + b + "]; return false; "
    }
  } else {
    r += " var err = " + b + ";  if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; "
  }
  r += " } "
  if (u) {
    r += " else { "
  }
  return r
}
